// 后台管理页面的tab
export default {
    state: {
        currentTabId: '' // 唤醒右键菜单的tabId
    },
    getters: {

    },
    mutations: {
        // 保存右键点击tab的id
        saveCurContextTabId (state, currentTabId) {
            state.currentTabId = currentTabId
        },
        // 关闭所有标签
        closeAllTabs (state) {
            state.tabs = [];
            this.commit("switchTab", "adminIndex")
        },
        /**
         * 关闭其它标签页
         * @param {*} state 
         * @param {*} type left 关闭左边; right 关闭右边; other关闭其他
         */
        closeOtherTabs (state, type) {
            let tabs = state.tabs;
            let length = tabs.length;
            let currentTabId = state.currentTabId;
            let activeTabItem = state.activeTabItem
            console.log(activeTabItem)
            let id; // 右键点击时的tab在整个tabs数组中的id
            let curId // 左键点击时的tab在整个tabs数组中的id
            tabs.forEach((tab, index) => {
                if (tab.id == currentTabId) {
                    id = index
                }
                if (tab.id == activeTabItem) {
                    curId = index
                }
            })
            if (type == "left") {
                if (id > curId) {
                    this.commit("switchTab", currentTabId)
                }
                state.tabs = state.tabs.slice(id, length)
            }
            if (type == "right") {
                if (id < curId) {
                    this.commit("switchTab", currentTabId)
                }
                state.tabs = state.tabs.slice(0, id + 1)
            }
            if (type == "other") {
                state.tabs = [state.tabs[curId]]
            }
        }
    }
}